package org.teremail.store;

import javax.sql.DataSource;

import org.junit.After;
import org.teremail.tx.SimpleTransactionManaer;

public abstract class AbstractTxTestCase extends AbstractStoreTestCase {

    private SimpleTransactionManaer tm;
    private DataSource ds;
    
    protected abstract DataSource createDataSource();
    
    public DataSource getDataSource() {
        return ds;
    }
    
    public void setUpInsideTX() throws Exception {}
    public void setUpOutsideTX() throws Exception {}
    public void tearDownInsideTX() throws Exception {}
    public void tearDownOutsideTX() throws Exception {}
    
    @Override
    public void onSetup() throws Exception {
        
        tm = new SimpleTransactionManaer();
        ds = tm.setDataSource(createDataSource());
        
        setUpOutsideTX();
        
        tm.begin();
        
        setUpInsideTX();
        
    }
    
    
    @After
    public void endTX() throws Exception {
        
        tearDownInsideTX();
        
        tm.commit();
        
        tearDownOutsideTX();
    }

}
